package com.cedarhd.brzx.domain.service;

import com.cedarhd.brzx.common.utils.DateUtil;
import com.cedarhd.brzx.common.utils.FileUtil;
import com.cedarhd.brzx.dto.request.CreateMemberDTO;
import com.cedarhd.brzx.dto.request.RealAuthDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author Evan
 * @date 2018/4/27
 */
@Service
public class FileService {
    @Value("${tonglian.txtPath}")
    private String txtPath;

    /**
     * 开会员信息写入到txt
     * @param req
     */
    public void writeCreateMember(CreateMemberDTO req){
        Long cts = System.currentTimeMillis();
        String fileName = "createMember-"+ DateUtil.transferLongToDate("yyyyMM", cts) + ".txt";
        String path = txtPath+"/soa/";
        StringBuilder content = new StringBuilder();
        content.append(DateUtil.transferLongToDate("yyyy-MM-dd HH:mm:ss", cts));
        content.append("----开通会员:  bizUserId = ").append(req.getBizUserId());
        content.append(",memberType = ").append(req.getMemberType().name());
        content.append(",source = ").append(req.getSource().name());
        content.append("\r\n");
        FileUtil.writeFile(path,fileName,content.toString());
    }

    /**
     * 开能会员返回结果
     * @param response
     */
    public void writeCreateMemberResponse(String response){
        Long cts = System.currentTimeMillis();
        String fileName = "createMemberResponse-"+ DateUtil.transferLongToDate("yyyyMM", cts) + ".txt";
        String path = txtPath+"/soa/";
        StringBuilder content = new StringBuilder();
        content.append(DateUtil.transferLongToDate("yyyy-MM-dd HH:mm:ss", cts));
        content.append("----开通会员返回结果:  response = ").append(response);
        content.append("\r\n");
        FileUtil.writeFile(path,fileName,content.toString());
    }

    /**
     * 实名认证写入到txt
     * @param realAuthDTO
     */
    public void writeSetRealName(RealAuthDTO realAuthDTO) {
        Long cts = System.currentTimeMillis();
        String fileName = "setRealName-"+ DateUtil.transferLongToDate("yyyyMM", cts) + ".txt";
        String path = txtPath+"/soa/";
        StringBuilder content = new StringBuilder();
        content.append(DateUtil.transferLongToDate("yyyy-MM-dd HH:mm:ss", cts));
        content.append("----实名认证:  bizUserId = ").append(realAuthDTO.getBizUserId());
        content.append(",name = ").append(realAuthDTO.getName());
        content.append(",isAuth = ").append(realAuthDTO.getIsAuth());
        content.append(",identityNo").append(realAuthDTO.getIdentityNo());
        content.append("\r\n");
        FileUtil.writeFile(path,fileName,content.toString());

    }

    /**实名认证返回结果写入到txt
     *
     * @param response
     */
    public void writeSetRealNameResponse(String response) {
        Long cts = System.currentTimeMillis();
        String fileName = "writeSetRealNameResponse-"+ DateUtil.transferLongToDate("yyyyMM", cts) + ".txt";
        String path = txtPath+"/soa/";
        StringBuilder content = new StringBuilder();
        content.append(DateUtil.transferLongToDate("yyyy-MM-dd HH:mm:ss", cts));
        content.append("----实名认证:  response = ").append(response);
        content.append("\r\n");
        FileUtil.writeFile(path,fileName,content.toString());
    }

    /**
     * 企业信息审核结果通知
     * @param response
     */
    public void writeVerifyResult(String response){
        Long cts = System.currentTimeMillis();
        String fileName = "verifyResult-"+ DateUtil.transferLongToDate("yyyyMM", cts) + ".txt";
        String path = txtPath+"/soa/";
        StringBuilder content = new StringBuilder();
        content.append(DateUtil.transferLongToDate("yyyy-MM-dd HH:mm:ss", cts));
        content.append("----企业信息审核结果通知:  response = ").append(response);
        content.append("\r\n");
        FileUtil.writeFile(path,fileName,content.toString());
    }
}
